<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Java 修饰符 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../java/java-modifier-types.html" />
<meta name="keywords" content="Java 修饰符">
<meta name="description" content="Java 修饰符 Java语言提供了很多修饰符，主要分为以下两类：  访问修饰符 非访问修饰符   修饰符用来定义类、方法或者变量，通常放在语句的最前端。我们通过下面的例子来说明：    [mycode3 type=&#039;java&#039;] public class ClassName {    // ... } private boolean myFlag; static final double weeks = 9.5; ..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>Java 教程</span>
	<a data-cate="53" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="53" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="Java 教程"  href="../java/java-tutorial.html" >
			Java 教程			</a>
						<a target="_top" title="Java 简介"  href="../java/java-intro.html" >
			Java 简介			</a>
						<a target="_top" title="Java 开发环境配置"  href="../java/java-environment-setup.html" >
			Java 开发环境配置			</a>
						<a target="_top" title="Java 基础语法"  href="../java/java-basic-syntax.html" >
			Java 基础语法			</a>
						<a target="_top" title="Java 对象和类"  href="../java/java-object-classes.html" >
			Java 对象和类			</a>
						<a target="_top" title="Java 基本数据类型"  href="../java/java-basic-datatypes.html" >
			Java 基本数据类型			</a>
						<a target="_top" title="Java 变量类型"  href="../java/java-variable-types.html" >
			Java 变量类型			</a>
						<a target="_top" title="Java 修饰符"  href="../java/java-modifier-types.html" >
			Java 修饰符			</a>
						<a target="_top" title="Java 运算符"  href="../java/java-operators.html" >
			Java 运算符			</a>
						<a target="_top" title="Java 循环结构 &#8211; for, while 及 do&#8230;while"  href="../java/java-loop.html" >
			Java 循环结构			</a>
						<a target="_top" title="Java 条件语句 &#8211; if&#8230;else"  href="../java/java-if-else-switch.html" >
			Java 条件语句			</a>
			<a target="_top" title="Java switch case 语句" href="../java/java-switch-case.html">Java switch case</a>			<a target="_top" title="Java Number &#038; Math 类"  href="../java/java-number.html" >
			Java Number & Math 类			</a>
						<a target="_top" title="Java Character 类"  href="../java/java-character.html" >
			Java Character 类			</a>
						<a target="_top" title="Java String 类"  href="../java/java-string.html" >
			Java String 类			</a>
						<a target="_top" title="Java StringBuffer 和 StringBuilder 类"  href="../java/java-stringbuffer.html" >
			Java StringBuffer			</a>
						<a target="_top" title="Java 数组"  href="../java/java-array.html" >
			Java 数组			</a>
						<a target="_top" title="Java 日期时间"  href="../java/java-date-time.html" >
			Java 日期时间			</a>
						<a target="_top" title="Java 正则表达式"  href="../java/java-regular-expressions.html" >
			Java 正则表达式			</a>
						<a target="_top" title="Java 方法"  href="../java/java-methods.html" >
			Java 方法			</a>
						<a target="_top" title="Java 流(Stream)、文件(File)和IO"  href="../java/java-files-io.html" >
			Java Stream、File、IO			</a>
			<a target="_top" title="Java Scanner 类" href="java-scanner-class.html"> Java Scanner 类 </a>			<a target="_top" title="Java 异常处理"  href="../java/java-exceptions.html" >
			Java 异常处理			</a>
			<br><h2 class="left">Java <span class="left_h2">面向对象</span></h2>			<a target="_top" title="Java 继承"  href="../java/java-inheritance.html" >
			Java 继承			</a>
						<a target="_top" title="Java 重写(Override)与重载(Overload)"  href="../java/java-override-overload.html" >
			Java Override/Overload			</a>
						<a target="_top" title="Java 多态"  href="../java/java-polymorphism.html" >
			Java 多态			</a>
						<a target="_top" title="Java 抽象类"  href="../java/java-abstraction.html" >
			Java 抽象类			</a>
						<a target="_top" title="Java 封装"  href="../java/java-encapsulation.html" >
			Java 封装			</a>
						<a target="_top" title="Java 接口"  href="../java/java-interfaces.html" >
			Java 接口			</a>
			<a target="_top" title="Java 枚举" href="../java/java-enum.html">
			Java 枚举			</a>			<a target="_top" title="Java 包(package)"  href="../java/java-package.html" >
			Java 包(package)			</a>
			<br><h2 class="left">Java <span class="left_h2">高级教程</span></h2>			<a target="_top" title="Java 数据结构"  href="../java/java-data-structures.html" >
			Java 数据结构			</a>
						<a target="_top" title="Java 集合框架"  href="../java/java-collections.html" >
			Java 集合框架			</a>
			<a target="_top" title="Java ArrayList" href="../java/java-arraylist.html">Java ArrayList</a>
<a target="_top" title="Java LinkedList" href="../java/java-linkedlist.html">Java LinkedList</a>
<a target="_top" title="Java HashSet" href="../java/java-hashset.html">Java HashSet</a>
<a target="_top" title="Java  HashMap" href="../java/java-hashmap.html">Java  HashMap</a>
<a target="_top" title="Java  Iterator" href="../java/java-iterator.html">Java  Iterator</a>
<a target="_top" title="Java  Object" href="../java/java-object-class.html">Java  Object</a>			<a target="_top" title="Java 泛型"  href="../java/java-generics.html" >
			Java 泛型			</a>
						<a target="_top" title="Java 序列化"  href="../java/java-serialization.html" >
			Java 序列化			</a>
						<a target="_top" title="Java 网络编程"  href="../java/java-networking.html" >
			Java 网络编程			</a>
						<a target="_top" title="Java 发送邮件"  href="../java/java-sending-email.html" >
			Java 发送邮件			</a>
						<a target="_top" title="Java 多线程编程"  href="../java/java-multithreading.html" >
			Java 多线程编程			</a>
						<a target="_top" title="Java Applet 基础"  href="../java/java-applet-basics.html" >
			Java Applet 基础			</a>
						<a target="_top" title="Java 文档注释"  href="../java/java-documentation.html" >
			Java 文档注释			</a>
						<a target="_top" title="Java 实例"  href="../java/java-examples.html" >
			Java 实例			</a>
						<a target="_top" title="Java 8  新特性"  href="../java/java8-new-features.html" >
			Java 8  新特性			</a>
						<a target="_top" title="Java MySQL 连接"  href="../java/java-mysql-connect.html" >
			Java MySQL 连接			</a>
						<a target="_top" title="Java 9 新特性"  href="../java/java9-new-features.html" >
			Java 9 新特性			</a>
			<a target="_blank" title="Java 测验" href="../quiz/java-quiz.html">Java 测验</a>	
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../java/java-variable-types.html" rel="prev"> Java 变量类型</a> </div>
			<div class="next-design-link"><a href="../java/java-operators.html" rel="next"> Java 运算符</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			<h1>Java 修饰符</h1>
<p>Java语言提供了很多修饰符，主要分为以下两类：</p>
<ul>
<li>访问修饰符</li>
<li>非访问修饰符</li>
</ul>
<p>
修饰符用来定义类、方法或者变量，通常放在语句的最前端。我们通过下面的例子来说明：
</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">ClassName</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-comment">//</span><span class="hl-comment"> ...</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-types">boolean</span><span class="hl-code"> </span><span class="hl-identifier">myFlag</span><span class="hl-code">;
</span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">weeks</span><span class="hl-code"> = </span><span class="hl-number">9</span><span class="hl-number">.5</span><span class="hl-code">;
</span><span class="hl-reserved">protected</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">BOXWIDTH</span><span class="hl-code"> = </span><span class="hl-number">42</span><span class="hl-code">;
</span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">arguments</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-comment">//</span><span class="hl-comment"> 方法体</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<hr>
<h2>
访问控制修饰符
</h2>
<p>Java中，可以使用访问控制符来保护对类、变量、方法和构造方法的访问。Java 支持 4 种不同的访问权限。</p>
<ul><li>
<p><strong>default</strong> (即默认，什么也不写）: 在同一包内可见，不使用任何修饰符。使用对象：类、接口、变量、方法。</p></li><li>
<p><strong>private</strong> : 在同一类内可见。使用对象：变量、方法。 <strong>注意：不能修饰类（外部类）</strong></p></li><li>
<p><strong>public</strong> : 对所有类可见。使用对象：类、接口、变量、方法</p></li><li>
<p><strong>protected</strong> : 对同一包内的类和所有子类可见。使用对象：变量、方法。 <strong>注意：不能修饰类（外部类）</strong>。</p></li></ul>
<p>我们可以通过以下表来说明访问权限：</p>
<table class="reference">
<caption style="font-weight: bold;font-size:16px;font-weight: bold;" id="accesscontrol-levels">访问控制</caption>
<tbody><tr>
<th>修饰符</th>
<th>当前类</th>
<th>同一包内</th>
<th>子孙类(同一包)</th>
<th>子孙类(不同包)</th>
<th>其他包</th>
</tr>
<tr>
<td headers="h1"><code>public</code></td>
<td headers="h2">Y</td>
<td headers="h3">Y</td>
<td headers="h4">Y</td>
<td headers="h5">Y</td>
<td headers="h6">Y</td>
</tr>
<tr>
<td headers="h1"><code>protected</code></td>
<td headers="h2">Y</td>
<td headers="h3">Y</td>
<td headers="h4">Y</td>

<td headers="h5">Y/N（<a href="#protected-desc">说明</a>）</td>
<td headers="h6">N</td>
</tr>
<tr>
<td headers="h1"><code>default</code></td>
<td headers="h2">Y</td>
<td headers="h3">Y</td>
<td headers="h4">Y</td>
<td headers="h5">N</td>
<td headers="h6">N</td>
</tr>
<tr>
<td headers="h1"><code>private</code></td>
<td headers="h2">Y</td>
<td headers="h3">N</td>
<td headers="h4">N</td>
<td headers="h5">N</td>
<td headers="h6">N</td>
</tr>
</tbody></table>
<h3>默认访问修饰符-不使用任何关键字</h3>
<p>
使用默认访问修饰符声明的变量和方法，对同一个包内的类是可见的。接口里的变量都隐式声明为 <span class="marked">public static final</span>,而接口里的方法默认情况下访问权限为 <span class="marked">public</span>。
</p>
<p>
如下例所示，变量和方法的声明可以不使用任何修饰符。
</p>
<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">version</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">1.5.1</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-types">boolean</span><span class="hl-code"> </span><span class="hl-identifier">processOrder</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-reserved">true</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>

<h3>私有访问修饰符-private</h3>

<p>私有访问修饰符是最严格的访问级别，所以被声明为 <strong>private</strong> 的方法、变量和构造方法只能被所属类访问，并且类和接口不能声明为 <strong>private</strong>。</p>
<p>声明为私有访问类型的变量只能通过类中公共的 getter 方法被外部类访问。</p>
<p>Private 访问修饰符的使用主要用来隐藏类的实现细节和保护类的数据。</p>
<p>下面的类使用了私有访问修饰符：</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Logger</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">format</span><span class="hl-code">;
   </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">getFormat</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-reserved">this</span><span class="hl-code">.</span><span class="hl-identifier">format</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">setFormat</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">format</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-reserved">this</span><span class="hl-code">.</span><span class="hl-identifier">format</span><span class="hl-code"> = </span><span class="hl-identifier">format</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>
实例中，Logger 类中的 format 变量为私有变量，所以其他类不能直接得到和设置该变量的值。为了使其他类能够操作该变量，定义了两个 public 方法：getFormat() （返回 format的值）和 setFormat(String)（设置 format 的值）
</p>
<h3>公有访问修饰符-public</h3>

<p>被声明为 public 的类、方法、构造方法和接口能够被任何其他类访问。
</p><p>如果几个相互访问的 public 类分布在不同的包中，则需要导入相应 public 类所在的包。由于类的继承性，类所有的公有方法和变量都能被其子类继承。
</p><p>
以下函数使用了公有访问控制：</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">arguments</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-comment">//</span><span class="hl-comment"> ...</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>Java 程序的 main() 方法必须设置成公有的，否则，Java 解释器将不能运行该类。</p>

<h3 id="protected-desc">受保护的访问修饰符-protected</h3>
<p>protected 需要从以下两个点来分析说明：</p>
<ul>
<li><p><strong>子类与基类在同一包中</strong>：被声明为 protected 的变量、方法和构造器能被同一个包中的任何其他类访问；</p></li>
<li><p><strong>子类与基类不在同一包中</strong>：那么在子类中，子类实例可以访问其从基类继承而来的 protected 方法，而不能访问基类实例的protected方法。</p></li>
</ul>
<p>protected 可以修饰数据成员，构造方法，方法成员，<strong>不能修饰类（内部类除外）</strong>。</p>
<p>接口及接口的成员变量和成员方法不能声明为 protected。 可以看看下图演示：
</p>
<p><img decoding="async" src="//www.runoob.com/wp-content/uploads/2013/12/java-protected.gif"></p>

<p>子类能访问 protected 修饰符声明的方法和变量，这样就能保护不相关的类使用这些方法和变量。
</p><p>
下面的父类使用了 protected 访问修饰符，子类重写了父类的 openSpeaker() 方法。</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">AudioPlayer</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-reserved">protected</span><span class="hl-code"> </span><span class="hl-types">boolean</span><span class="hl-code"> </span><span class="hl-identifier">openSpeaker</span><span class="hl-brackets">(</span><span class="hl-identifier">Speaker</span><span class="hl-code"> </span><span class="hl-identifier">sp</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-comment">//</span><span class="hl-comment"> 实现细节</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">StreamingAudioPlayer</span><span class="hl-code"> </span><span class="hl-reserved">extends</span><span class="hl-code"> </span><span class="hl-identifier">AudioPlayer</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-reserved">protected</span><span class="hl-code"> </span><span class="hl-types">boolean</span><span class="hl-code"> </span><span class="hl-identifier">openSpeaker</span><span class="hl-brackets">(</span><span class="hl-identifier">Speaker</span><span class="hl-code"> </span><span class="hl-identifier">sp</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-comment">//</span><span class="hl-comment"> 实现细节</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>

<p>如果把 openSpeaker() 方法声明为 private，那么除了 AudioPlayer 外，其他类将不能访问该方法。</p><p>
如果把 openSpeaker() 声明为 public，那么所有的类都能够访问该方法。</p><p>
如果我们只想让该方法对其所在类的子类可见，则将该方法声明为 protected。</p>
</p>



<blockquote><p>protected 是最难理解的一种 Java 类成员访问权限修饰词，更多详细内容请查看 <a href="../w3cnote/java-protected-keyword-detailed-explanation.html" rel="noopener noreferrer" target="_blank">Java protected 关键字详解</a>。</p></blockquote>


<h3>访问控制和继承</h3>
<p>

请注意以下方法继承的规则：
</p>
<ul>
	<li><p>父类中声明为 public 的方法在子类中也必须为 public。</p>
	</li>
	<li><p>父类中声明为 protected 的方法在子类中要么声明为 protected，要么声明为 public，不能声明为 private。</p>
	</li>
	
	<li>
		<p>
			父类中声明为 private 的方法，不能够被子类继承。</p>
	</li>
</ul>




<hr>
<h2>
非访问修饰符</h2>
<p>为了实现一些其他的功能，Java 也提供了许多非访问修饰符。</p>
<p>static 修饰符，用来修饰类方法和类变量。</p>
<p>final 修饰符，用来修饰类、方法和变量，final 修饰的类不能够被继承，修饰的方法不能被继承类重新定义，修饰的变量为常量，是不可修改的。</p>
<p>abstract 修饰符，用来创建抽象类和抽象方法。</p>
<p>synchronized 和 volatile 修饰符，主要用于线程的编程。</p>
<h3>static 修饰符</h3>
<ul>
<li>
<p><strong>静态变量：</strong><p>
static 关键字用来声明独立于对象的静态变量，无论一个类实例化多少对象，它的静态变量只有一份拷贝。
静态变量也被称为类变量。局部变量不能被声明为 static 变量。
</li><li>
<p><strong>静态方法：</strong><p>
static 关键字用来声明独立于对象的静态方法。静态方法不能使用类的非静态变量。静态方法从参数列表得到数据，然后计算这些数据。
</li></ul>
<p>
对类变量和方法的访问可以直接使用 <strong>classname.variablename</strong> 和 <strong>classname.methodname</strong> 的方式访问。
</p>
<p>
如下例所示，static 修饰符用来创建类方法和类变量。</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">InstanceCounter</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">numInstances</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
   </span><span class="hl-reserved">protected</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">getCount</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">numInstances</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
 
   </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">addInstance</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">numInstances</span><span class="hl-code">++;
   </span><span class="hl-brackets">}</span><span class="hl-code">
 
   </span><span class="hl-identifier">InstanceCounter</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">InstanceCounter</span><span class="hl-code">.</span><span class="hl-identifier">addInstance</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
 
   </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">arguments</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Starting with </span><span class="hl-quotes">&quot;</span><span class="hl-code"> +
      </span><span class="hl-identifier">InstanceCounter</span><span class="hl-code">.</span><span class="hl-identifier">getCount</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> + </span><span class="hl-quotes">&quot;</span><span class="hl-string"> instances</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
      </span><span class="hl-reserved">for</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">i</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-identifier">i</span><span class="hl-code"> &lt; </span><span class="hl-number">500</span><span class="hl-code">; ++</span><span class="hl-identifier">i</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
         </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">InstanceCounter</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
          </span><span class="hl-brackets">}</span><span class="hl-code">
      </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Created </span><span class="hl-quotes">&quot;</span><span class="hl-code"> +
      </span><span class="hl-identifier">InstanceCounter</span><span class="hl-code">.</span><span class="hl-identifier">getCount</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> + </span><span class="hl-quotes">&quot;</span><span class="hl-string"> instances</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>以上实例运行编辑结果如下:</p>
<pre>
Starting with 0 instances
Created 500 instances
</pre>
<h3>final 修饰符</h3>
<p><strong>final 变量：</strong></p>

<p>final 表示"最后的、最终的"含义，变量一旦赋值后，不能被重新赋值。被 final 修饰的实例变量必须显式指定初始值。</p>
<p>final 修饰符通常和 static 修饰符一起使用来创建类常量。</p>

<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Test</span><span class="hl-brackets">{</span><span class="hl-code">
  </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">value</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
  </span><span class="hl-comment">//</span><span class="hl-comment"> 下面是声明常量的实例</span><span class="hl-comment"></span><span class="hl-code">
  </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">BOXWIDTH</span><span class="hl-code"> = </span><span class="hl-number">6</span><span class="hl-code">;
  </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">TITLE</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">Manager</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
 
  </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">changeValue</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
     </span><span class="hl-identifier">value</span><span class="hl-code"> = </span><span class="hl-number">12</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">将输出一个错误</span><span class="hl-comment"></span><span class="hl-code">
  </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p><strong>final 方法</strong></p>
<p>父类中的 final 方法可以被子类继承，但是不能被子类重写。</p>
<p>声明 final 方法的主要目的是防止该方法的内容被修改。</p>
<p>如下所示，使用 final 修饰符声明方法。</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Test</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">changeName</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
       </span><span class="hl-comment">//</span><span class="hl-comment"> 方法体</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p><strong>final 类</strong></p>
<p>final 类不能被继承，没有类能够继承 final 类的任何特性。</p>
<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">final</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Test</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-comment">//</span><span class="hl-comment"> 类体</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<h3>abstract 修饰符</h3>
<p><strong>抽象类：</strong></p>
<p>抽象类不能用来实例化对象，声明抽象类的唯一目的是为了将来对该类进行扩充。
</p><p>一个类不能同时被 abstract 和 final 修饰。如果一个类包含抽象方法，那么该类一定要声明为抽象类，否则将出现编译错误。
</p><p>抽象类可以包含抽象方法和非抽象方法。
</p>

<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">abstract</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Caravan</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">price</span><span class="hl-code">;
   </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">model</span><span class="hl-code">;
   </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">year</span><span class="hl-code">;
   </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">abstract</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">goFast</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">抽象方法</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">abstract</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">changeColor</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p><strong>抽象方法</strong></p>
<p>
抽象方法是一种没有任何实现的方法，该方法的具体实现由子类提供。</p><p>抽象方法不能被声明成 final 和 static。
</p><p>任何继承抽象类的子类必须实现父类的所有抽象方法，除非该子类也是抽象类。
</p><p>如果一个类包含若干个抽象方法，那么该类必须声明为抽象类。抽象类可以不包含抽象方法。
</p><p>抽象方法的声明以分号结尾，例如：<strong>public abstract sample();</strong>。
</p>
<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">abstract</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">SuperClass</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">abstract</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">m</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">抽象方法</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">SubClass</span><span class="hl-code"> </span><span class="hl-reserved">extends</span><span class="hl-code"> </span><span class="hl-identifier">SuperClass</span><span class="hl-brackets">{</span><span class="hl-code">
     </span><span class="hl-comment">//</span><span class="hl-comment">实现抽象方法</span><span class="hl-comment"></span><span class="hl-code">
      </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">m</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
          .........
      </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<h3>synchronized 修饰符</h3>
<p>synchronized 关键字声明的方法同一时间只能被一个线程访问。synchronized 修饰符可以应用于四个访问修饰符。
</p>
<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">synchronized</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">showDetails</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
.......
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<h3>transient 修饰符</h3>

<p>序列化的对象包含被 transient 修饰的实例变量时，java 虚拟机(JVM)跳过该特定的变量。
</p><p>该修饰符包含在定义变量的语句中，用来预处理类和变量的数据类型。
</p>
<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">transient</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">limit</span><span class="hl-code"> = </span><span class="hl-number">55</span><span class="hl-code">;   </span><span class="hl-comment">//</span><span class="hl-comment"> 不会持久化</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 持久化</span><span class="hl-comment"></span></div>
</div>
</div>
<h3>volatile 修饰符</h3>

<p>volatile 修饰的成员变量在每次被线程访问时，都强制从共享内存中重新读取该成员变量的值。而且，当成员变量发生变化时，会强制线程将变化值回写到共享内存。这样在任何时刻，两个不同的线程总是看到某个成员变量的同一个值。</p>
<p>一个 volatile 对象引用可能是 null。
</p>
<div class="example">
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">MyRunnable</span><span class="hl-code"> </span><span class="hl-reserved">implements</span><span class="hl-code"> </span><span class="hl-identifier">Runnable</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">private</span><span class="hl-code"> </span><span class="hl-reserved">volatile</span><span class="hl-code"> </span><span class="hl-types">boolean</span><span class="hl-code"> </span><span class="hl-identifier">active</span><span class="hl-code">;
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">run</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">active</span><span class="hl-code"> = </span><span class="hl-reserved">true</span><span class="hl-code">;
        </span><span class="hl-reserved">while</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">active</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> 第一行</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-brackets">{</span><span class="hl-code">
            </span><span class="hl-comment">//</span><span class="hl-comment"> 代码</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">stop</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">active</span><span class="hl-code"> = </span><span class="hl-reserved">false</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 第二行</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>
通常情况下，在一个线程调用 run() 方法（在 Runnable 开启的线程），在另一个线程调用 stop() 方法。
如果 <strong><em>第一行</em></strong> 中缓冲区的 active 值被使用，那么在 <strong><em>第二行</em></strong> 的 active 值为 false 时循环不会停止。
</p><p>
但是以上代码中我们使用了 volatile  修饰 active，所以该循环会停止。</p>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../java/java-variable-types.html" rel="prev"> Java 变量类型</a> </div>
			<div class="next-design-link"><a href="../java/java-operators.html" rel="next"> Java 运算符</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">12  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment byuser comment-author-tianqixin bypostauthor even thread-even depth-1" id="comment-10376"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;tianqixin</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;429***967@qq.com</p></div><div id="runoobvote-id-10376" data-commid = "10376" class="upvotejs"><a class="upvote"></a> <span class="count">175</span></div></div><div class="comt-main" id="div-comment-10376"><p>JAVA 的类（外部类）有 2 种访问权限: public、default。</p><p>
而方法和变量有 4 种：public、default、protected、private。</p><p>
其中默认访问权限和 protected 很相似，有着细微的差别。</p>
<ul><li>
public 意味着任何地方的其他类都能访问。</li><li>
default 则是同一个包的类可以访问。</li><li>
protected 表示同一个包的类可以访问，其他的包的该类的子类也可以访问。</li><li>
private 表示只有自己类能访问。</li></ul>

<p><strong>修饰符：abstract、static、final</strong></p>
<ul><li>
abstract: 表示是抽象类。 使用对象：类、接口、方法</li><li>
static: 可以当做普通类使用，而不用先实例化一个外部类。（用他修饰后，就成了静态内部类了）。 使用对象：类、变量、方法、初始化函数（注意：修饰类时只能修饰 内部类 ）</li><li>
final: 表示类不可以被继承。 使用对象：类、变量、方法</li></ul><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">tianqixin</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;tianqixin</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;429***967@qq.com</p></div></span>6年前 (2017-03-24)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-10412"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;大白小爱</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;362***275@qq.com</p></div><div id="runoobvote-id-10412" data-commid = "10412" class="upvotejs"><a class="upvote"></a> <span class="count">231</span></div></div><div class="comt-main" id="div-comment-10412"><p>整个世界都打包成一块，同时划分为四个层次: 联合国（public）【其他包】、国家（protected）【继承子孙】、洲际（default）【同一包】、个人（private）【当前类】。 </p><p>
联合国制定规则所有人都可以用，国家制定的只有在国家内可以用，各联邦洲因地制宜有制定当地民法，个人制定的就给个人使用。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">大白小爱</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;大白小爱</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;362***275@qq.com</p></div></span>6年前 (2017-03-25)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-12823"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;dsfsdf</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;dsf***@126.com</p></div><div id="runoobvote-id-12823" data-commid = "12823" class="upvotejs"><a class="upvote"></a> <span class="count">39</span></div></div><div class="comt-main" id="div-comment-12823"><p><strong>static全局变量与普通的全局变量：</strong>static全局变量只初使化一次，防止在其他文件单元中被引用;</p>

<p><strong>static局部变量和普通局部变量：</strong>static局部变量只被初始化一次，下一次依据上一次结果值；</p>
<p><strong>static函数与普通函数：</strong>static函数在内存中只有一份，普通函数在每个被调用中维持一份拷贝。</p>

<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">dsfsdf</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;dsfsdf</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;dsf***@126.com</p></div></span>6年前 (2017-06-09)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-15116"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Real</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;zen***0522@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://zhidao.baidu.com/question/105782131.html">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-15116" data-commid = "15116" class="upvotejs"><a class="upvote"></a> <span class="count">79</span></div></div><div class="comt-main" id="div-comment-15116"><p>静态变量并不是说其就不能改变值，不能改变值的量叫常量。 其拥有的值是可变的 ，而且它会保持最新的值。说其静态，是因为它不会随着函数的调用和退出而发生变化。即上次调用函数的时候，如果我们给静态变量赋予某个值的话，下次函数调用时，这个值保持不变。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Real</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Real</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;zen***0522@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://zhidao.baidu.com/question/105782131.html">&nbsp;&nbsp;参考地址</a></p></div></span>6年前 (2017-07-19)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-15282"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Charlie Lee</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;101***4851@qq.com</p></div><div id="runoobvote-id-15282" data-commid = "15282" class="upvotejs"><a class="upvote"></a> <span class="count">37</span></div></div><div class="comt-main" id="div-comment-15282"><p><b>关于修饰符</b>：</p><p>1.分为“访问修饰符”和“非访问修饰符”。顾名思义，“访问修饰符”就是和访问权限有关得修饰符。</p><p>2.访问修饰符中一些值得注意得地方：</p><p>Private 访问修饰符的使用主要用来隐藏类的实现细节和保护类的数据；</p><p>被声明为 public 的类、方法、构造方法和接口能够被任何其他类访问；</p><p>protected 访问修饰符可以修饰类及其方法，但是接口及接口的成员变量和成员方法不能声明为 protected；</p><p>3.关于static修饰符的理解</p><p>怎么理解静态变量呢？简单来说静态变量就是一个类的公有属性。在这里可以打个拙劣的比方：假设“班里的学生”是一个类，班里的任何一个同学都相当于一个对象。那么所有学生的学费是一样的对吧？”学费“就相当于一个”静态变量“，其特征是它不属于任何一个”对象“（即学生）的专有属性，是大家”公有“的，若是变了，那就所有的同学的学费都会变。我们假设每个同学都有修改学费的权力，那么任何一个同学修改了学费（这个静态变量），所有同学的学费就都会变。</p><p></p><p>另外：静态方法只能使用类的静态变量。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Charlie Lee</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Charlie Lee</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;101***4851@qq.com</p></div></span>6年前 (2017-07-23)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-17182"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;啥也不想</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;tri***lboy@163.com</p></div><div id="runoobvote-id-17182" data-commid = "17182" class="upvotejs"><a class="upvote"></a> <span class="count">47</span></div></div><div class="comt-main" id="div-comment-17182"><p><strong>transient</strong></p>
<p>当对象被序列化时（写入字节序列到目标文件）时，transient阻止实例中那些用此关键字声明的变量持久化；当对象被反序列化时（从源文件读取字节序列进行重构），这样的实例变量值不会被持久化和恢复。</p>
<pre>import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

//定义一个需要序列化的类

class People implements Serializable{
    String name; //姓名
    transient Integer age; //年龄
    public People(String name,int age){
        this.name = name;
        this.age = age;
    }

    public String toString(){
        return "姓名 = "+name+" ,年龄 = "+age;
    }

}

public class TransientPeople {
    public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
        People a = new People("李雷",30);
        System.out.println(a); //打印对象的值
        ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("d://people.txt"));
        os.writeObject(a);//写入文件(序列化)
        os.close();
        ObjectInputStream is = new ObjectInputStream(new FileInputStream("d://people.txt"));
        a = (People)is.readObject();//将文件数据转换为对象（反序列化）
        System.out.println(a); // 年龄 数据未定义
        is.close();
    }
}</pre>


<p>运行结果如下：</p>


<pre>姓名 = 李雷 ,年龄 = 30
姓名 = 李雷 ,年龄 = null</pre>


<p><strong>volatile</strong></p>

<p>volatile可以用在任何变量前面，但不能用于final变量前面，因为final型的变量是禁止修改的。</p>
<p>使用的场景之一，单例模式中采用DCL双锁检测（double checked locking）机制，在多线程访问的情况下，可使用volatitle修改，保证多线程下的可见性。缺点是性能有损失，因此单线程情况下不必用此修饰符。</p>



<pre>class Singleton{
    private volatile static Singleton instance = null;
    private Singleton() {
    }

    public static Singleton getInstance() {
        if(instance==null) {
            synchronized (Singleton.class) {
                if(instance==null)
                    instance = new Singleton();
            }
        }
        return instance;
    }
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">啥也不想</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;啥也不想</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;tri***lboy@163.com</p></div></span>6年前 (2017-09-05)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-17647"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;xhm_hm</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;504***020@qq.com</p></div><div id="runoobvote-id-17647" data-commid = "17647" class="upvotejs"><a class="upvote"></a> <span class="count">16</span></div></div><div class="comt-main" id="div-comment-17647"><p><strong>关于final变量:</strong></p>
<ul><li>
1、 final 修饰符通常和 static 修饰符一起使用来创建类常量。用final修饰的成员变量表示常量，值一旦给定就无法改变！
</li><li>
2、 final修饰的变量有三种：静态变量、实例变量和局部变量，分别表示三种类型的常量。final变量定义的时候，可以先声明，而不给初值，这中变量也称为final空白，无论什么情况，编译器都确保空白final在使用之前必须被初始化。但是，final空白在final关键字final的使用上提供了更大的灵活性，为此，一个类中的final数据成员就可以实现依对象而有所不同，却有保持其恒定不变的特征。</li></ul><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">xhm_hm</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;xhm_hm</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;504***020@qq.com</p></div></span>6年前 (2017-09-16)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-21325"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;happywith</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;735***469@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://blog.csdn.net/zhangjk1993/article/details/24196847">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-21325" data-commid = "21325" class="upvotejs"><a class="upvote"></a> <span class="count">34</span></div></div><div class="comt-main" id="div-comment-21325"><p>final以及final static修饰的变量的初始化方式：</p>
<pre>
    //-----------------成员变量------------------//  
    //初始化方式一，在定义变量时直接赋值  
    private final int i = 3;  
  
    //初始化方式二,声明完变量后在构造方法中为其赋值  
    //如果采用用这种方式，那么每个构造方法中都要有j赋值的语句  
    private final int j;  
  
    public FinalTest() {  
        j = 3;  
    }  
  
    //如果取消该构造方法的注释，程序就会报错，因此它没有为j赋值  
    /*public FinalTest1(String str) { 
 
    }*/  
  
    //为了方便我们可以这样写  
    public FinalTest(String str) {  
        this();  //调用无参构造器
    }  
  
    //下面的代码同样会报错，因为对j重复赋值  
    /*public FinalTest1(String str1, String str2) { 
        this(); 
        j = 3; 
    }*/  
  
  
    //初始化方式三，声明完变量后在构造代码块中为其赋值  
    //如果采用此方式，就不能在构造方法中再次为其赋值  
    //构造代码块中的代码会在构造函数之前执行，如果在构造函数中再次赋值，  
    //就会造成final变量的重复赋值  
    private final int k;  
  
    {  
        k = 4;  
    }  
  
    //-----------------类变量（静态变量）------------------//  
    //初始化方式一，在定义类变量时直接赋值  
    public final static int p = 3;  
  
    //初始化方式二，在静态代码块中赋值  
    //成员变量可以在构造函数中赋值，但是类变量却不可以。  
    //因此成员变量属于对象独有，每个对象创建时只会调用一次构造函数，  
    //因此可以保证该成员变量只被初始化一次；  
    //而类变量是该类的所有对象共有，每个对象创建时都会对该变量赋值  
    //这样就会造成变量的重复赋值。  
    public final static int q;  
  
    static {  
        q = 3;  
    }</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">happywith</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;happywith</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;735***469@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://blog.csdn.net/zhangjk1993/article/details/24196847">&nbsp;&nbsp;参考地址</a></p></div></span>5年前 (2017-12-07)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-33595"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;冰雨</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;614***768@qq.com</p></div><div id="runoobvote-id-33595" data-commid = "33595" class="upvotejs"><a class="upvote"></a> <span class="count">23</span></div></div><div class="comt-main" id="div-comment-33595"><p><strong>fina、static、abstract</strong> 之间不能同时使用的问题：</p>

<p>1、final 不能同时和 abstract 使用，例子：</p>

<pre>abstract final void m();</pre> 

<p><strong>原因：</strong>因为 abstract 是需要被子类继承覆盖的，否则毫无意义，而 final 作用是禁止继承的，两者相互排斥，所以不呢能 共用。</p>
<p>2：static 和 abstract 也是不能连用的，例子：</p>
<pre>abstract static void m(){}</pre>

<p><strong>原因：</strong>因为 static 是类级别的不能被子类覆盖，而 abstract 需要被继承实现，两者相互矛盾。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">冰雨</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;冰雨</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;614***768@qq.com</p></div></span>5年前 (2018-08-04)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-48303"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;ytj神墨癸</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yua***1999@outlook.com</p></div><div id="runoobvote-id-48303" data-commid = "48303" class="upvotejs"><a class="upvote"></a> <span class="count">18</span></div></div><div class="comt-main" id="div-comment-48303"><p>准确来说，protected 关键字表示可以访问 this 和 super 中的对应成员，而不能访问（非同包的）其他类实例中的对应成员。</p>

<p>比如，Object 类是所有 Java 类的基类，有一个 protected 的 clone() 方法。我们可以在一个类的方法中调用 this.clone()，也可以调用 super.clone()，但不能调用（非同包且没有把这个方法提升为 public 权限的）其他子类实例中的 clone()。如果按照“能被子类访问”来理解的话， Object.clone() 的这个 protected 就没有意义了，因为所有类都是 Object 的子类，那样就和 public 没差别了。</p>

<pre>/**
 * Object.java: 220
 * protected native Object clone() throws CloneNotSupportedException;
 */

public class MyClass /* extends Object */ {
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();   // OK.
    }

    public static Object bad(AnotherClassFromAnotherPackage obj) throws CloneNotSupportedException {
        return obj.clone();     // Error.
    }
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">ytj神墨癸</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;ytj神墨癸</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yua***1999@outlook.com</p></div></span>4年前 (2019-11-10)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-48876"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;赵铁锤</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;hbd***b@hotmail.com</p></div><div id="runoobvote-id-48876" data-commid = "48876" class="upvotejs"><a class="upvote"></a> <span class="count">27</span></div></div><div class="comt-main" id="div-comment-48876"><p>关于protected修饰符分享一点自己总结的规律：</p><p>遇到调用protected修饰的方法，沿着继承关系向上寻找此方法的最后一次实现是否和当前调用的地方处于同一个包内，如果是，那么可以调用，如果不是，那么不行。但有一种情况例外，如果向上寻找实现的时候路过了当前调用的地方所处的类，那么这种情况下即使本类没有实现这个方法，那也是可以编译通过的。</p><p></p><p>其实对于protected的理解通俗点讲就是，这个方法，只有你跟我在一起（同一个包）的时候才给你用，你不跟我在一起我就不给你用了。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">赵铁锤</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;赵铁锤</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;hbd***b@hotmail.com</p></div></span>3年前 (2019-11-28)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-59294"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;胡友</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;190***3839@qq.com</p></div><div id="runoobvote-id-59294" data-commid = "59294" class="upvotejs"><a class="upvote"></a> <span class="count">24</span></div></div><div class="comt-main" id="div-comment-59294"><p>java访问权控制限修饰符：</p><p>&nbsp;private&lt;default&lt;<strong>protected&lt;public,权限重小到大不断递增。</strong></p><p><b>private 修饰在方法，属性，成员类上，可见性为本类;（被修饰后不能被继承）</b></p><p><b>default 修饰在类，方法，属性，成员类上，可见性为本包;</b></p><p><b>protected 修饰在方法，属性，成员类，可见性为本包，本子孙类;</b></p><p><b>public 修饰在类 ，方法，属性，成员类，可见性本包，外包，子孙类。</b></p><p><b>方法权限继承重写：重写的权限不能小于等于父类方法的权限。</b></p><p><b>非访问权限修控制修饰符</b><b>：</b></p><p><b>final:</b></p><p><b>修饰在类上：类不能被继承；</b></p><p><b>修饰在方法上：方法继承下来不能被重写；</b></p><p><b>修饰在属性上：属性只能被赋值一次，没有给默认值，必须在构造方法中赋值。</b></p><p>static:</p><p>修饰在成员变量和方法上，被其修饰的方法和变量从属于类优先加载在方法区，使其能被在堆内存中未加载的对象进行共享访问，static 不能修饰在局部语句块中的变量，因为无法共享该数据，被static修饰的方法不能在该方法里访问该类的对象属性和方法，因为当初始化static修饰的方法和成员变量语句块时，对象还未加载在堆内存，就还没有this对象的引用，就无法访问对象的方法和属性。如需访问必须先把对象new出来。</p><p>abstract:</p><p>abstract修饰类与方法上，修饰在类上就是是抽象类，抽象类中的方法可以被abstract修饰不写花括号以分号结尾，就是抽象方法；</p><p>synchronize：</p><p>synchronize关键字修饰在方法上，在多线程中使用，该方法同一时间只能被一个线程访问，锁就是this</p><p>transient:</p><p>修饰在包含定义变量的语句中将不会被序列化存储在硬盘</p>volatile<p>修饰在成员变量上，在多线程中访问该变量，都会重新从线程中获取，使真实数据可见。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">胡友</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;胡友</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;190***3839@qq.com</p></div></span>2年前 (2020-12-06)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='4993' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  4993;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 4993, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":4993},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 4993;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>